
<template>
  <div class="banxin modal" v-show="$store.state.Gologin">
    <div class="modal_bg" @click="Delmodal"></div>
    <div class="modal_content">
      <section class="m_c_to">
        <span>登录</span>
        <div @click="Delmodal">x</div>
      </section>
      <div v-if="huantu">
        <div class="m_c_l">
          <img src="../assets/images/denglu.png" alt="" />
          <section>
            <h3>扫码登录</h3>
            <img :src="this.ErweimaTu" alt="" />
            <p>使用<a href="#">网易云音乐APP</a>扫码登录</p>
          </section>
        </div>
        <div class="btn" @click="goQita">选择其他登录模式</div>
      </div>
      <div v-else-if="huantu1" class="m_c_qita">
        <div class="m_c_qita_l">
          <div></div>
          <button @click="goQital">手机号登录</button>
          <button>注册</button>
          <p>
            <input type="checkbox" v-model="checkBox" />
            同意
            <a href="#">《服务条款》</a>
            <a href="#">《隐私政策》</a>
            <a href="#">《儿童隐私政策》</a>
          </p>
        </div>
        <div class="m_c_qita_r">
          <ul>
            <li>
              <div class="tu1"></div>
              <h4>微信登录</h4>
            </li>
            <li>
              <div class="tu2"></div>
              <h4>QQ登录</h4>
            </li>
            <li>
              <div class="tu3"></div>
              <h4>微博登录</h4>
            </li>
            <li>
              <div class="tu4"></div>
              <h4>网易邮箱账号登录</h4>
            </li>
          </ul>
          <span class="fanhui" @click="goQita"> 返回 </span>
        </div>
      </div>

      <div v-else class="phonelogin">
        <input
          class="phonecode"
          type="text"
          placeholder="请输入手机号"
          v-model="phone"
        />
        <div class="verify_box">
          <slide-verify
            :l="42"
            :r="10"
            :w="360"
            :h="155"
            slider-text="向右滑动"
            @success="onSuccess"
            @fail="onFail"
            @refresh="onRefresh"
          ></slide-verify>
          <div>{{ msg }}</div>
        </div>
        <div class="yanzheng">
          <input type="text" placeholder="请输入验证码" v-model="code" />
          <button @click="huoquyanzheng">获取验证码</button>
        </div>
        <button class="phonebtn" @click="yanzheng">登录</button>
        <span class="mima">密码登录</span>
        <div class="weibu">
          <span @click="goQital">&#8592; 其他登录方式 </span>
          <span>没有账号?其他登录方式 &#8594;</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
const vaildatephone = (phone) => {
  let reg =
    /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  return reg.test(phone.trim());
};

import {
  GeLoginApi,
  GetYanzhengmaApi,
  GetErweimaApi,
  GetErweimatuApi,
} from "../request/api";
export default {
  data() {
    return {
      //到微信页面
      huantu: true,
      //到验证码页面
      huantu1: true,
      //滑块正确
      huakuai: "",
      msg: "",
      phone: "",
      code: "",
      //同意
      checkBox: false,
      //二维码生成的key
      ErweimaKey: "",
      //二维码地址
      ErweimaTu: "",
      // Ohonedd: {
      //   phone: "15681539907",
      //   captcha: "4718",
      // },
    };
  },
  methods: {
    //关闭模态框
    Delmodal() {
      this.$store.commit("chageLogin", false);
    },
    //切换登录方式
    goQita() {
      this.huantu = !this.huantu;
    },
    goQital() {
      if (!this.checkBox == true) {
        let Title = {
          content: "请先勾选同意注意事项",
          icon: "info",
        };
        this.$store.dispatch("AsyncToast", Title);
        return;
      }
      this.huantu1 = !this.huantu1;
    },
    //滑块
    onSuccess() {
      this.msg = "验证成功";
      this.huakuai = true;
    },
    onFail() {
      this.msg = "验证失败";
      this.huakuai = false;
    },
    onRefresh() {
      this.msg = "";
    },
    //获取验证码
    huoquyanzheng() {
      console.log(this.phone);
      let ret = vaildatephone(this.phone);
      if (!ret || this.huakuai !== true) {
        let Title = {
          content: "请正确输入手机号或滑块",
          icon: "info",
        };
        this.$store.dispatch("AsyncToast", Title);
        return;
      }
      if (ret || this.huakuai == true) {
        let Title = {
          content: "发送成功",
          icon: "success",
        };
        this.$store.dispatch("AsyncToast", Title);
      }
      GeLoginApi({ phone: this.phone }).then((res) => {
        console.log(res);
      });
      // if(ret||this.code)
    },
    //验证验证码
    async yanzheng() {
      console.log("iiii");
      let res = await GetYanzhengmaApi({
        phone: this.phone,
        captcha: this.code,
      }).then((res) => {
        if (res.data.code == 503) {
          let Title = {
            content: res.data.message,
            icon: "info",
          };
          console.log(res);
          this.$store.dispatch("AsyncToast", Title);
        }
        if (res.data.code == 200) {
          localStorage.setItem("x-auth-token", res.data["x-auth-token"]);
          let Title = {
            content: "登录成功",
            icon: "success",
          };
          console.log(res);
          this.$store.dispatch("AsyncToast", Title);
        }
      });
      this.$store.commit("chageLogin", false);
      return res;
    },
  },
  created() {
    GetErweimaApi().then((res) => {
      this.ErweimaKey = res.data.data.unikey;
      console.log(this.ErweimaKey);
      return;
    });
    GetErweimatuApi({ key: this.ErweimaKey, qrimg: "1" }).then((res) => {
      this.ErweimaTu = res.data.data.qrurl;

      console.log(res);
    });
  },
};
</script>
 
<style lang = "less" scoped>
@import "../assets/base.less";
.modal {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  .modal_bg {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
  }
  .modal_content {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    width: 660px;
    height: 460px;
    background-color: white;
    .m_c_to {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 30px;
      background: black;
      span {
        padding-left: 10px;
        font-weight: bold;
        color: #ccc;
      }
      div {
        width: 20px;
        height: 30px;
        color: #ccc;
        cursor: pointer;
      }
    }
    .m_c_l {
      display: flex;
      img {
        height: 300px;
        margin-left: 150px;
        margin-top: 30px;
      }
      section {
        margin-top: 35px;
        margin-left: 20px;
        h3 {
          text-align: center;
          margin-bottom: 30px;
        }
        img {
          width: 200px;
          height: 200px;
          margin: auto;
        }
        p {
          margin-top: 10px;
        }
      }
    }
    .btn {
      width: 150px;
      height: 30px;
      margin-left: 40%;
      margin-top: 20px;
      line-height: 30px;
      text-align: center;
      border-radius: 15px 15px 15px 15px;
      border: 1px solid #cccfcc;
    }
  }
}
.m_c_qita {
  display: flex;
}
.m_c_qita_l {
  width: 70%;
  div {
    height: 160px;
    width: 280px;
    background: url(../assets/images/denglu2.png) no-repeat;
    background-size: contain;
    margin-left: 140px;
    margin-top: 60px;
  }
  button {
    width: 280px;
    margin-bottom: 10px;
    height: 30px;
    border-style: none;
    margin-left: 140px;
    &:nth-of-type(1) {
      background-color: #3787d2;
      color: white;
    }
  }
  p {
    font-size: 14px;
    margin-top: 30px;
    margin-left: 60px;
    a {
      text-decoration: none;
      color: #3787d2;
      &:hover {
        text-decoration: underline;
      }
    }
  }
}
.m_c_qita_r {
  border-left: 1px solid #ccc;
  width: 35%;
  padding-left: 20px;
  box-sizing: border-box;
  padding-top: 20px;
  li {
    margin-top: 20px;
    display: flex;
    /* justify-content: center; */
    align-items: center;
    .tu1 {
      height: 48px;
      width: 40px;
      background: url(../assets/images/jinglingtu.png) no-repeat -150px -666px;
    }
    .tu2 {
      height: 48px;
      width: 40px;
      background: url(../assets/images/jinglingtu.png) no-repeat -190px -666px;
    }
    .tu3 {
      height: 48px;
      width: 40px;
      background: url(../assets/images/jinglingtu.png) no-repeat -230px -666px;
    }
    .tu4 {
      height: 48px;
      width: 40px;
      background: url(../assets/images/jinglingtu.png) no-repeat -270px -666px;
    }
    h4 {
      padding-left: 10px;
      &:hover {
        text-decoration: underline;
      }
    }
  }
  .fanhui {
    position: absolute;
    bottom: 20px;
    right: 20px;
  }
}
.phonelogin {
  width: 100%;
  position: relative;
  .phonecode {
    width: 350px;
    height: 30px;
    padding-left: 10px;
    margin-left: 23%;
    margin-top: 80px;
    outline-style: none;
    border-radius: 15px 15px 15px 15px;
  }
  .yanzheng {
    box-sizing: border-box;
    input {
      width: 230px;
      height: 30px;
      padding-left: 10px;
      margin-left: 23%;
      border-radius: 15px 15px 15px 15px;
      outline-style: none;
    }
    button {
      margin-left: 20px;
      width: 100px;
      height: 33px;
      color: white;
      border: none;
      border-radius: 15px 15px 15px 15px;
      background-color: @orange;
    }
  }
  .phonebtn {
    width: 350px;
    height: 30px;
    padding-left: 10px;
    margin-top: 20px;
    margin-left: 23%;
    border: none;
    border-radius: 15px 15px 15px 15px;
    background-color: @orange;
    color: white;
    font-weight: bolder;
  }
  .mima {
    display: block;
    margin-left: 20px;
    padding-top: 50px;
    margin-bottom: 30px;
    &:hover {
      color: #3787d2;
      text-decoration: underline;
    }
  }
  .weibu {
    display: flex;
    justify-content: space-between;
    span {
      color: #cccfcc;
      margin-top: 20px;
      &:hover {
        color: #3787d2;
        text-decoration: underline;
      }
    }
  }
}
.verify_box {
  width: 360px;
  margin: 0 auto 20px;
  /deep/.slide-verify {
    width: 100% !important;
    canvas {
      position: absolute;
      top: -150px;
      left: 0;
      display: none;
      box-sizing: border-box;
    }
    &:hover {
      canvas {
        display: block;
      }
    }
  }
}
</style>